package com.zbf.JaMiJieMi;

import lombok.SneakyThrows;

import javax.servlet.ServletInputStream;
import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author: LCG
 * @date: 2023-02-10 17:03:40
 * @description:
 **/
public class AdviceHttpServletRequestWapper extends HttpServletRequestWrapper {



    public AdviceHttpServletRequestWapper(HttpServletRequest request) {
        super(request);
    }

    @Override
    public Map<String, String[]> getParameterMap() {
        return super.getParameterMap();
    }

    @SneakyThrows
    @Override
    public ServletRequest getRequest() {
        ServletRequest request = super.getRequest();
        ServletInputStream inputStream = request.getInputStream();
        InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
        try{
            String encodeAesContent = new BufferedReader(inputStreamReader).lines().collect(Collectors.joining(System.lineSeparator()));
        }finally {
            inputStreamReader.close();
        }

        return request;
    }
}
